// ignore_for_file: use_super_parameters, prefer_const_literals_to_create_immutables, prefer_const_constructors, avoid_print

import 'package:flutter/material.dart';
import 'package:flutter_getx_1/page/state/getx/controller.dart';
import 'package:get/get.dart';

/*
 * GetX 局部自动控制
 * controller -> update
*/
class GetxView extends StatelessWidget {
  GetxView({ Key? key }) : super(key: key);
  final controller = AddController();
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("Getx"),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            Text("GetX<AddController>{build:(){}}"),
            SizedBox(height: 20,),
            GetX<AddController>(
              init: controller,
              initState: (_){},
              builder: (_) {
                print("GetX obj - 1");
                return Text('value obj 1 -> ${_.obj}');
              }
            ),
            SizedBox(height: 20,),
            GetX<AddController>(
              init: controller,
              initState: (_) {},
              builder: (_){
                return Column(
                  children: <Widget>[
                    Text("value obj 2 -> ${_.obj}"),
                    SizedBox(height: 10,),
                    ElevatedButton(
                      onPressed: () => _.objadd(),
                      child: Text("obj(GetX<AddController>)里面返回的按钮",)
                    )
                  ],
                );
              },
            ),
            SizedBox(height: 30,),
            GetX<AddController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print("GetX num - 4");
                return Text('value num -> ${_.num}');
              },
            ),
            SizedBox(height: 20,),
            ElevatedButton(onPressed: () => controller.objadd(), child: Text("obj")),
            SizedBox(height: 20,),
            ElevatedButton(onPressed: () => controller.numadd(), child: Text("num"))
          ],
        ),
      ),
    );
  }
}